﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Way.EAP.DataAccess.Entity;
using Way.EAP.DataAccess.Regulation;
using Way.Bus.WMS.Controllers;
using Way.Contract.MVC;
using Way.Bus.WMS.Model;
using Way.Contract.Data.ControllerData;
using Way.Contract.Data;

namespace Way.Bus.WMS.SF.Controllers
{
    /// <summary>
    /// 产品入库
    /// 创建人：柳强
    /// 创建时间：2013-07-12
    /// </summary>
    public class StockPurchaseInOrderController : StockInOrderController
    {
        #region 初始化数据方法

        //显示在菜单
        protected override string OnControllerName()
        {
            return "产品入库";
        }
        //菜单中url路径
        protected override string OnGetPath()
        {
            return "Views/SF/StockPurchaseInOrder.htm";
        }
        //说明
        protected override string OnGetControllerDescription()
        {
            return "产品入库管理";
        }

        /// <summary>
        /// 启用下推
        /// </summary>
        public override bool IsPushDown
        {
            get
            {
                return false;
            }
        }
        #endregion

        #region 初始化数据方法
        protected override void OnInitViewChildItem(Contract.Data.ModelData data, Contract.Data.ItemData item)
        {
            base.OnInitViewChildItem(data, item);
            if (data.name.EndsWith("StockInOrder"))
            {
                data.title = "产品入库";
                switch (item.field.ToLower())
                {
                    case "code":
                        item.index = 1;
                        break;
                    case "remark":
                        item.visible = true;
                        item.index = 2;
                        break;
                    case "towhno":
                        item.visible = true;
                        item.index = 3;
                        break;
                    case "rowindex":
                    case "createdby":
                    case "creationdate":
                    case "issubmited":
                    case "submitedby":
                    case "submiteddate":
                    case "isreviewed":
                    case "reviewedby":
                    case "revieweddate":
                        item.visible = true;
                        break;
                    default:
                        item.visible = false;
                        break;
                }
            }
            if (data.name.EndsWith("Materials"))
            {
                data.title = "原料入库明细";
                switch (item.field.ToLower())
                {
                    case "materialcode":
                        item.index = 1;
                        break;
                    case "mcode":
                        item.disabled = true;
                        item.index = 2;
                        break;
                    case "fmodel":
                        item.disabled = true;
                        item.index = 3;
                        break;
                    case "num":
                    case "remark":
                        item.visible = true;
                        break;
                    default:
                        item.visible = false;
                        break;
                }
            }
            if (data.name.EndsWith("StockInNoticeMaterials") || data.name.EndsWith("InSequence"))
                data.visible = false;
        }

        #endregion

        protected override ActionCommand[] OnInitCommand(ActionCommand[] commands)
        {
            //获取所有按钮集合
            foreach (ActionCommand ac in commands)
            {
                if (ac.command == "ReviewedData")
                {
                    ac.visible = false;
                }
            }
            return commands;
        }

        protected override void OnAdding(ControllerBase.SaveEvent item)
        {
            base.OnAdding(item);
            StockInOrder ord = item.Item as StockInOrder;
            ord.STOCKTYPE = 0;//生产入库
        }
        protected override void OnEditing(ControllerBase.SaveEvent item)
        {
            base.OnEditing(item);
            StockInOrder ord = item.Item as StockInOrder;
            ord.STOCKTYPE = 0;//生产入库
        }
        public override void LostBill(Bus.Model.BasicInfo info)
        {
            //base.LostBill(info);
        }
        protected override void OnForeignLoading(IModel model, loadItem item)
        {
            ///选择仓库
            if (this.fdata.filedname == "TOWHNO")
            {
                SQLWhere tempSql = new SQLWhere();
                tempSql.ColumnName = "Acc_WMS_WareHouse.WHTYPE";
                tempSql.Relation = "and";
                tempSql.Type = "int";
                tempSql.Value = "0";
                List<SQLWhere> tempList = new List<SQLWhere>();
                tempList.Add(tempSql);
                item.whereList = tempList.ToArray();
            }
            base.OnForeignLoading(model, item);
        }

        protected override void OnGetWhereing(IModel m, List<SQLWhere> where, loadItem item)
        {
            base.OnGetWhereing(m, where, item);
            if (m is StockInOrder)
            {
                SQLWhere tempSql = new SQLWhere();
                tempSql.ColumnName = "Acc_WMS_InOrder.STOCKTYPE";
                tempSql.Value = "0";
                where.Add(tempSql);
            }
            
        }
    }
}
